﻿#region itdc

/************************************************************************
*Copyright(C) 2015 by qsgy
 *All rights reserved. 
 *FileName:     $safeitemname$
 *Author:       oyh
 *Version:      
 *UnityVersion：
 *Date:   $time$      
 *Description:    
 *History: 
************************************************************************/
#endregion
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//预警器,
public class Alarm : MonoBehaviour {
    #region 1

    public Material[] mt;
    bool isAlert = false;

    #endregion

    //预警，变成红色
    public void Alert()
    {
        
        transform.Find("color").GetComponent<Renderer>().material = mt[1];
        isAlert = true;
    }

    //从预警变成不预警状态
    public void NoAlert()
    {
        transform.Find("color").GetComponent<Renderer>().material = mt[0];
        isAlert = false;
    }

    //是否处于预警状态
    public void IsAlert()
    {
        // Application.ExternalCall("IsAlert",  isAlert);

        ByteBuffer bf = ByteBuffer.Allocate(12);
        bf.WriteShort(10);
        bf.WriteUTF("isalert");
        bf.WriteBoolean(isAlert);
        SocketFace.instance.SendBuf(bf);
    }


    private void OnTriggerEnter(Collider other)
    {
        Alert();
        IsAlert();
    }

    private void OnTriggerExit(Collider other)
    {
        NoAlert();
        IsAlert();
    }

    private void OnTriggerStay(Collider other)
    {
        Alert();
    }
}
